package com.java_senior_8;

import java.util.Scanner;

public class MainApp {
    public static void mainMenu(){
        System.out.println("============学员信息管理系统============");
        System.out.println("|         0.查询学员信息            |");
        System.out.println("|         1.显示学员信息            |");
        System.out.println("|         2.新增学员信息            |");
        System.out.println("|         3.修改学员信息            |");
        System.out.println("|         4.删除学员信息            |");
        System.out.println("|         5.安全退出系统            |");

    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        boolean isExit;
        do{
            isExit = true;
            mainMenu();
            System.out.print("请选择:");
            try {
                int choose = input.nextInt();
                switch (choose){
                    case 0:
                        System.out.println("请输入学号");
                        int num=input.nextInt();
                        for (Student stu: StudentManager.getStudentList(num)) {
                            System.out.println(stu.getId()+stu.getName()+stu.getSex()+stu.getAge());
                        }
                        break;
                    case 1:
                        StudentManager.showAllStudent();
                        break;
                    case 2:
                        Student student = new Student();
                        System.out.print("请输入学号:");
                        student.setId(input.nextInt());
                        System.out.print("请输入姓名:");
                        student.setName(input.next());
                        System.out.print("请输入性别:");
                        student.setSex(input.next());
                        System.out.print("请输入年龄:");
                        student.setAge(input.nextInt());
                        boolean isSuc = StudentManager.addStudent(student);
                        if(isSuc){
                            System.out.println("新增学员信息成功！");
                        }
                        else{
                            System.out.println("新增学员信息失败！");
                        }
                        break;
                    case 3:
                        Student student1 = new Student();
                        System.out.print("请输入学号:");
                        student1.setId(input.nextInt());
                        System.out.print("请输入姓名:");
                        student1.setName(input.next());
                        System.out.print("请输入性别:");
                        student1.setSex(input.next());
                        System.out.print("请输入年龄:");
                        student1.setAge(input.nextInt());

                        if (  StudentManager.updateStudent(student1)){
                            System.out.println("修改成功");
                        }

                        break;
                    case 4:
                        System.out.println("请输入学号");
                        int num1=input.nextInt();
                       if ( StudentManager.deleteStudentById(num1)){
                           System.out.println("删除成功");
                       }

                        break;

                    case 5:
                        System.out.println("谢谢使用本系统v1.0");
                        isExit = false;
                        break;
                }
            }catch (Exception ex){
                System.out.println("输入有误,请重新输入");
                input = new Scanner(System.in);
            }
        }while (isExit);

    }
}
